/***
 * 根据后台返回list<Object> 解析渲染表格
 * @param data list数据
 * @param count 表格中隐藏域的数量,隐藏域必须放在最前边
 * @returns {String} 返回表格数据
 * 
 * 表格样式必须为 .layui-table 表头必须thead th中设置字段属性fileds 值为list对象中的属性
 * 如果 fileds 中存在fid id属性则设置为checkbox
 * 此方法最后带操作列 调用方法必须实现由del eidt 方法 并入参为fid 或者 id
 */
function pageDataCheck(data,count){
	var items = new Array();
	var idx = 0;
	$('.layui-table thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = "";  
	var id = "";
	$.each(data,function(n,t) {   
           trs += "<tr>";
           $.each(items,function(i,m) { 
        	   var val = t[m];
        	   if($.isNull(val)){
        		   val = "";
        	   }
        	   if(m== 'ftype'){
        		   val =  $(window.parent.getTdic(val));
        		   val = val.selector;
        	   }
        	   if(i < count){
        		   trs +="<input type='hidden' name="+m+" value="+val+" >"
        	   }else{
        		   if(m == "fid" || m == "id"){
        			   trs += "<td><input type='checkbox' id ='id' name="+m+" value="+val+" /></td>	";
        			   id = val;
        		   }else{
        			   trs += "<td>"+val+"</td>";
        		   }
        	   }
           });
           var c ="border-red";
           if(t.ffire == 1){
        	   c ="";
           }
           var top ="border-red";
           if(t.ftop == 1){
        	   top ="";
           }
     	   trs +="<td> ";
     	   trs +=" <div class='button-group'> <a class='button border-red' id="+id+" href='javascript:void(0)' onclick='del(this.id)'>";
     	   trs +=" <i class='layui-icon '>&#xe640;</i></a></div>"; 
     	   trs +=" <div class='button-group' >";
     	   trs +=" <a class='button border-red' href='javascript:void(0)' id="+id+" onclick='eidt(this.id)'>";
     	   trs +=" <i class='layui-icon'>&#xe642;</i> </a> </div></td></tr>";
    });
    return trs;
}

function pageGridCheck(table,data,count){
	var items = new Array();
	var idx = 0;
	$(table).find('thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = "";  
	var id = "";
	$.each(data,function(n,t) {   
           trs += "<tr>";
           $.each(items,function(i,m) { 
        	   var val = t[m];
        	   if($.isNull(val)){
        		   val = "";
        	   }
        	   if(m== 'ftype'){
        		   val =  $(window.parent.getTdic(val));
        		   val = val.selector;
        	   }
        	   if(i < count){
        		   trs +="<input type='hidden' name="+m+" value="+val+" >"
        	   }else{
        		   if(m == "fid" || m == "id"){
        			   trs += "<td><input type='checkbox' id ='id' name="+m+" value="+val+" /></td>	";
        			   id = val;
        		   }else{
        			   trs += "<td>"+val+"</td>";
        		   }
        	   }
           });
           var c ="border-red";
           if(t.ffire == 1){
        	   c ="";
           }
           var top ="border-red";
           if(t.ftop == 1){
        	   top ="";
           }
     	   trs +="<td> ";
     	   trs +=" <div class='button-group'> <a class='button border-red' id="+id+" href='javascript:void(0)' onclick='prew(this.id)'>";
    	   trs +=" <i class='layui-icon'>&#xe63c;</i></a></div>"; 
           if(t.fstatus ==0){
        	   trs +=" <div class='button-group'> <a class='button border-red' id="+id+" href='javascript:void(0)' onclick='del(this.id)'>";
         	   trs +=" <i class='layui-icon '>&#xe640;</i></a></div>"; 
         	   trs +=" <div class='button-group' >";
         	   trs +=" <a class='button border-red' href='javascript:void(0)' id="+id+" onclick='eidt(this.id)'>";
         	   trs +=" <i class='layui-icon'>&#xe642;</i> </a> </div>" ;
           }else{
        	   trs +=" <div class='button-group'> <a class='button border-red' id="+id+" href='javascript:void(0)' onclick='cancle(this.id)'>";
         	   trs +=" <i class='layui-icon '>&#x1006;</i></a></div>"; 
           }
     	   		
           trs +="</td></tr>";
    });
    return trs;
}
/***
 * 根据后台返回list<Object> 解析渲染表格
 * @param data list数据
 * @returns {String} 返回表格数据
 * 
 * 表格样式必须为 .layui-table 表头必须thead th中设置字段属性fileds 值为list对象中的属性
 * 第一列为序号,此方法只用来显示，不用来编辑
 */
function pageDataNum(data){
	var items = new Array();
	var idx = 0;
	$('.layui-table thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = ""; 
	$.each(data,function(n,t) {   
           trs += "<tr>";
           $.each(items,function(i,m) {
        	   var inx = n+1;
        	   var val = t[m];
        	   if($.isNull(val)){
        		   val = "";
        	   }
        	   if(i == 0){
        		   trs += "<td align=center>"+inx+"</td>";
        	   }else{
        		   trs += "<td>"+val+"</td>";
        	   }
           });
     	   trs +="</tr>";
    });
    return trs;
}
function pageDataMagic(data){
	var items = new Array();
	var idx = 0;
	$('.layui-table thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = "";  
	var id = "";
	var statetext = "";
	var event = "";
	var event2 = "";
	var event3 = "";
	$.each(data,function(n,t) {   
           trs += "<tr>";
           $.each(items,function(i,m) { 
        	   var val = t[m];
        	   var inx = n+1;
        	   if($.isNull(val)){
        		   val = "";
        	   }
        	   if(m == "fid" || m == "id"){
    			   id = val;
        	   }
        	   if(m == "fstats"){
        		   var fstate = val;
        		   if(fstate == "1"){
        			   //开启中，可暂停和可移除
        			   statetext = "暂停";
        			   var num = "state"+n+i;
        			   event = "stop(this,"+num+","+fstate+")";
        			   event2 = "remove(this,"+num+","+fstate+")";
        			   event3 = "startnow(this,"+num+")";
        			   val = "爬取中";
        		   }else if(fstate == "2"){
        			   //暂停中，可开启和可移除
        			   statetext = "开启";
        			   var num = "state"+n+i;
        			   event = "Wstats(this,"+num+","+fstate+")";
        			   event2 = "remove(this,"+num+","+fstate+")";
        			   event3 = "startnow(this,"+num+")";
        			   val = "已暂停";
        		   }else{
        			   //已移除， 可开启,不可移除
        			   var num = "state"+n+i;
        			   statetext = "开启";
        			   event = "Wstats(this,"+num+","+fstate+")";
        			   event2 = "remove(this,"+num+","+fstate+")";
        			   event3 = "startnow(this,"+num+")";
        			   val = "已移除";
        		   }
        	   }
        	   if(m== 'ftype'){
        		  
        		   val =  $(window.parent.getTdic(val));
        		   val = val.selector;
        	   }
        	   if(i == 0){
        		   trs += "<td align=center>"+inx+"</td>";
    		   }else if(i == 1){
    			   trs += "<td >"+
    			   			 "<a href='javascript:' style='color: #2f39ab' id="+id+" onclick='Winfo(this.id)'>"+val+"</a>"+
			    			 "<div style='float: right;margin-right: 50px;'><a href='javascript:' id="+id+" onclick='magiclog(this.id)' title='日志'>" +
				   		  		"<i class='layui-icon' style='font-size: 30px; color: red;'>&#xe637;</i>" +
				   		  	 "</a></div>"+
					   		 "<div style='float: right;margin-right: 20px;'><a href='javascript:' id="+id+" onclick='magic_grid(this.id)' title='数据'>" +
			  		  			"<i class='layui-icon' style='line-height: 25px;height: 25px;font-size: 35px; color: red;'>&#xe60a;</i>" +
			  		  		 "</a></div>"+
    			   		  "</td>"
    		   }else if(i == 2){
    			   trs += "<td style='width:10%'>"+val+"</td>";
    		   }else if(i == 3){
    			   trs += "<td id='state"+n+i+"'>"+val+"</td>";
    		   }else{
    			   trs += "<td>"+val+"</td>";
    		   }
           });
           var c ="border-red";
           if(t.ffire == 1){
        	   c ="";
           }
           var top ="border-red";
           if(t.ftop == 1){
        	   top ="";
           }
           
     	   trs +="<td> ";
     	   //trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='Winfo(this.id)'>详情</button></div>";
     	   //trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='magiclog(this.id)'>日志</button></div>"; 
     	   //trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='magic_grid(this.id)'>数据</button></div>"; 
     	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='"+event+"'>"+statetext+"</button></div>";
     	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='"+event2+"'>移除</button></div>";
     	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='"+event3+"'>立即执行</button></div>";
     	   trs +=" </td></tr>";
	});
    return trs;
}
/***
 * 公众号管理
 * @param table
 * @param data
 * @param count
 * @returns {String}
 */
function pageWechatCheck(data){
	var items = new Array();
	var idx = 0;
	$('.layui-table thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = "";  
	var id = "";
	$.each(data,function(n,t) {   
           trs += "<tr>";
           $.each(items,function(i,m) { 
        	   var val = t[m];
        	   var inx = n+1;
        	   if($.isNull(val)){
        		   val = "";
        	   }
        	   if(m == "fid" || m == "id"){
    			   id = val;
        	   }
        	   if(m== 'ftype'){
        		   val =  $(window.parent.getTdic(val));
        		   val = val.selector;
        	   }
        	   if(m== 'ftimer'){
        		   val =  $(window.parent.getTdic(val));
        		   val = val.selector;
        	   }
        	   if(i == 0){
        		   trs += "<td align=center>"+inx+"</td>";
    		   }else{
    			   trs += "<td>"+val+"</td>";
    		   }
           });
           var c ="border-red";
           if(t.ffire == 1){
        	   c ="";
           }
           var top ="border-red";
           if(t.ftop == 1){
        	   top ="";
           }
     	   trs +="<td> ";
     	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='Winfo(this.id)'>详情</button></div>";
     	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='magiclog(this.id)'>日志</button></div>"; 
     	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='magic_grid(this.id)'>数据</button></div>"; 
     	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='Wstats(this)'>发布</button></div>";
     	   trs +=" </td></tr>";
	});
    return trs;
}
/***
 * 文章上传
 * @param table
 * @param data
 * @param count
 * @returns {String}
 */
function pageGirdUp(data,count){
	var items = new Array();
	var idx = 0;
	$('#no_list thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = "";  
	var id = "";
	var c = 0;
	var direaction = "";
	$.each(data,function(n,t) {   
           trs += "<tr>";
           direaction = t['fareadySend'];
           $.each(items,function(i,m) { 
        	   var val = t[m];
        	   if($.isNull(val)){
        		   val = "";
        	   }  
        	   if(m== 'ftype'){
        		   val =  $(window.parent.getTdic(val));
        		   val = val.selector;
        	   }
        	   if(i < count){
        		   trs +="<input type='hidden' name="+m+" value="+val+" >"
        		   if(m == "fcounts" || m == "fcounts"){
        			   c = val;
        		   }
        		   if(m == "fid" || m == "id"){
        			   id = val;
        		   }
        	   }else{
        		   if(m == "fid" || m == "id"){
        			   trs += "<td><input type='checkbox' id ='id' name="+m+" value="+val+" /></td>	";
        			   id = val;
        		   }else{
        			   if(m == "ftitle" || m == "ftitle"){
        				   if(direaction != "" && direaction != null){
        					   trs += "<td id=td"+id+">"+val+"<span class='badge' style='background-color: red'>"+ c+"</span><div class='divtip'>"+direaction+"</div></td>";
        				   }else{
        					   trs += "<td id=td"+id+">"+val+"<span class='badge' style='background-color: red'>"+ c+"</span></td>";
        				   }
            			  
        			   }else{
            			   trs += "<td id=td"+id+">"+val+"</td>";
        			   }	
        		   }
        	   }
           });
     	   trs +="<td> ";
     	   trs +=" <div class='button-group'> <a class='button border-red' title='批量' id="+id+" href='javascript:void(0)' onclick='add(this.id)'>";
     	   trs +=" <i class='layui-icon '>&#xe608;</i></a></div>"; 
     	   trs +=" <div class='button-group' ><a class='button border-red' title='日志' href='javascript:void(0)' id="+id+" onclick='log(this.id)'>";
     	   trs +=" <i class='layui-icon'>&#xe60e;</i> </a> </div>";
     	   trs +=" <div class='button-group' ><a class='button border-red' title='发布' href='javascript:void(0)' id="+id+" onclick='send(this.id)'>";
    	   trs +=" <i class='layui-icon'>&#xe609;</i> </a> </div>";
    	   
     	   trs +="</td></tr>";
    });
    return trs;
}

/**
 * 
 * 网站管理
 */
function pageWebSiteCheck(data){
	var items = new Array();
	var idx = 0;
	$('.layui-table thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = "";  
	var id = "";
	$.each(data,function(n,t) {   
        trs += "<tr>";
        $.each(items,function(i,m) { 
     	   var val = t[m];
     	   var inx = n+1;
     	   if($.isNull(val)){
     		   val = "";
     	   }
     	   if(m == "fid" || m == "id"){
 			   id = val;
     	   }
     	   if(i == 0){
     		   trs += "<td align=center>"+inx+"</td>";
 		   }else{
 			   trs += "<td>"+val+"</td>";
 		   }
        });
        var c ="border-red";
        if(t.ffire == 1){
     	   c ="";
        }
        var top ="border-red";
        if(t.ftop == 1){
     	   top ="";
        }
  	   trs +="<td> ";
  	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='webSiteInfo(this.id)'>详情</button></div>";
  	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='siteLog(this.id)'>日志</button></div>"; 
  	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='magic_grid(this.id)'>数据</button></div>"; 
  	   trs +=" <div class='button-group'> <button class='layui-btn' id="+id+" onclick='Wstats(this)'>发布</button></div>";
  	   trs +=" </td></tr>";
	});
	return trs;
}
function pageDataCode(data){
	var items = new Array();
	var idx = 0;
	var id = "";
	$('.layui-table thead tr').children().each(function () {
		 var fileds = $(this).attr("id");//获取属性
		 if(!$.isNull(fileds)){
			 items[idx] = fileds;
			 idx=idx+1;
		 }
    });
	var trs = ""; 
	$.each(data,function(n,t) {   
           trs += "<tr>";
           $.each(items,function(i,m) {
        	   var inx = n+1;
        	   var val = t[m];
        	   if($.isNull(val)){
        		   val = "";
        	   }
        	   if(m== 'ftype'){
	    		   val =  $(window.parent.getTdic(val));
	    		   val = val.selector;
	    	   }
        	   if(m == "fid" || m == "id"){
	 			   id = val;
	     	   }
        	   if(i == 0){
//      		   trs += "<td align=center>"+inx+"</td>";
        		   trs += "<td><input type='checkbox' id ='id' name="+m+" value="+val+" /></td>	";
        	   }else{
        		   trs += "<td>"+val+"</td>";
        	   }
           });
           trs +="<td> ";
           trs +=" <div class='button-group'> <button class='layui-btn layui-btn-mini' id="+id+" onclick='del(this.id)'>删除</button></div>";
  	   	   trs +=" <div class='button-group'> <button class='layui-btn layui-btn-mini' id="+id+" onclick='edit(this.id)'>修改</button></div>";
     	   trs +="</td></tr>";
    });
    return trs;
}